-
-
Notifications
You must be signed in to change notification settings - Fork 468
Fix erroneous order of events for multi events per listener #1885
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
$id = $reference->__toString(); | ||
foreach ($container->getDefinition($id)->getTag('doctrine.orm.entity_listener') as $attributes) { | ||
foreach ($container->findTaggedServiceIds('doctrine.orm.entity_listener') as $id => $tags) { | ||
usort($tags, static fn (array $a, array $b) => ($a['priority'] ?? 0) <=> ($b['priority'] ?? 0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be
usort($tags, static fn (array $a, array $b) => ($a['priority'] ?? 0) <=> ($b['priority'] ?? 0)); | |
usort($tags, static fn (array $a, array $b) => ($b['priority'] ?? 0) <=> ($a['priority'] ?? 0)); |
i.e. tags with a larger number as priority come first!?
foreach ($resolvers as $reference) { | ||
$id = $reference->__toString(); | ||
foreach ($container->getDefinition($id)->getTag('doctrine.orm.entity_listener') as $attributes) { | ||
foreach ($container->findTaggedServiceIds('doctrine.orm.entity_listener') as $id => $tags) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The next line will sort the tags within the service by priority but the services are now simply in the order they are returned by $container->findTaggedServiceIds()
, i.e., in the order they were defined.
But for the listeners to be registered in the correct order the tags of all services need to be ordered together.
This probably needs to restructure the code to a single foreach
over all tags of all returned services?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So something like this:
$serviceTags = [];
foreach ($container->findTaggedServiceIds('doctrine.orm.entity_listener') as $id => $tags) {
foreach ($tags as $attributes) {
$serviceTags[] = [
'serviceId' => $id,
'attributes' => $attributes,
];
}
}
usort($serviceTags, static fn (array $a, array $b) => ($b['attributes']['priority'] ?? 0) <=> ($a['attributes']['priority'] ?? 0));
foreach ($serviceTags as $tag) {
$id = $tag['serviceId'];
$attributes = $tag['attributes'];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test I have added doesn't pass with such a change. Mind raising a PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #2029
Fixes #1884